import { defHttp } from '../http'
import type { CommonAPI } from '../model/_utils'

// 获取用户详细信息
export const userInfoApi: CommonAPI<'/v1/user/{id}', 'get'> = params =>
  defHttp.get(`/user/${params.id}`)

// 获取用户列表
export const userListApi: CommonAPI<'/v1/user', 'get'> = params =>
  defHttp.get('/user', { params })

// 新增用户
export const postUserApi: CommonAPI<'/v1/user', 'post'> = data =>
  defHttp.post('/user', { data })

// 修改用户
export const putUserApi: CommonAPI<'/v1/user/{id}', 'put'> = data =>
  defHttp.put(`/user/${data.id}`, { data })

// 重置用户密码
export const resetUserPasswordApi: CommonAPI<
  '/v1/user/{id}/password',
  'put'
> = data => defHttp.put(`/user/${data.id}/password`, { data })

// 修改用户dns服务器
export const putUserDnsApi: CommonAPI<'/v1/user/{id}/ns', 'put'> = data =>
  defHttp.put(`/user/${data.id}/ns`, { data })

// 获取用户组列表
export const userGroupListApi: CommonAPI<'/v1/user_group', 'get'> = params =>
  defHttp.get('/user_group', { params })

// 获取用户组信息
export const userGroupInfoApi: CommonAPI<
  '/v1/user_group/{id}',
  'get'
> = params => defHttp.get(`/user_group/${params.id}`)

// 新增用户组
export const postUserGroupApi: CommonAPI<'/v1/user_group', 'post'> = data =>
  defHttp.post('/user_group', { data })

// 修改用户组
export const putUserGroupApi: CommonAPI<'/v1/user_group/{id}', 'put'> = data =>
  defHttp.put(`/user_group/${data.id}`, { data })

// 删除用户组
export const deleteUserGroupApi: CommonAPI<
  '/v1/user_group/{id}',
  'delete'
> = params => defHttp.delete(`/user_group/${params.id}`)

// 加入用户组
export const joinUserGroup: CommonAPI<
  '/v1/user_group/{id}/users',
  'put'
> = data => defHttp.put(`/user_group/${data.id}/users`, { data })

// 获取用户域名组列表
export const userDomainGroupListApi: CommonAPI<
  '/v1/domain_group',
  'get'
> = params => defHttp.get('/domain_group', { params })

// 新增用户域名组
export const postUserDomainGroupApi: CommonAPI<
  '/v1/domain_group',
  'post'
> = data => defHttp.post('/domain_group', { data })

// 修改用户域名组
export const putUserDomainGroupApi: CommonAPI<
  '/v1/domain_group/{id}',
  'put'
> = data => defHttp.put(`/domain_group/${data.id}`, { data })

// 删除用户域名组
export const deleteUserDomainGroupApi: CommonAPI<
  '/v1/domain_group/{id}',
  'delete'
> = params => defHttp.delete(`/domain_group/${params.id}`)

// 加入域名到用户域名组
export const joinUserDomainGroupApi: CommonAPI<
  '/v1/domain_group/{id}/domains',
  'put'
> = data => defHttp.put(`/domain_group/${data.id}/domains`, { data })

// 批量删除用户域名组
export const deleteUserDomainGroupsApi: CommonAPI<
  '/v1/domain_groups',
  'delete'
> = data => defHttp.delete('/domain_groups', { data })

// 获取用户登录记录列表
export const userLoginRecordListApi: CommonAPI<
  '/v1/user_login_record',
  'get'
> = params => defHttp.get('/user_login_record', { params })

// 批量删除用户分组
export const deleteUserGroupBatchApi: CommonAPI<
  '/v1/user_groups',
  'delete'
> = data => defHttp.delete('/user_groups', { data })
